package com.sgb.kjwl.view.ui.activity.self.authentication;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.View;

import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.Observer;

import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.bigkoo.pickerview.view.TimePickerView;
import com.bumptech.glide.Glide;
import com.luck.picture.lib.entity.LocalMedia;
import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityOrganizationAuthBinding;
import com.sgb.kjwl.di.self.DaggerSelfComponent;
import com.sgb.kjwl.di.self.SelfModule;
import com.sgb.kjwl.model.entity.self.TeamAuthEntity;
import com.swgk.core.event.EventConstant;
import com.sgb.kjwl.view.event.LoginEvent;
import com.sgb.kjwl.view.event.self.AuthenticationEvent;
import com.swgk.core.util.PickSelectEntity;
import com.sgb.kjwl.model.entity.self.OrganizationAuthEntity;
import com.sgb.kjwl.model.entity.user.AddressEntity;
import com.sgb.kjwl.model.entity.user.AuthPhotoEntity;
import com.sgb.kjwl.utils.Constants;
import com.sgb.kjwl.view.ui.activity.WebActivity;
import com.swgk.core.view.CityPickBuilder;
import com.swgk.core.view.CityPickView;
import com.sgb.kjwl.viewmodel.self.authentication.OrganizationAuthModel;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.customview.CfkEditView;
import com.swgk.core.customview.ItemInputTextView;
import com.swgk.core.util.ClickUtils;
import com.swgk.core.util.DateUtils;
import com.swgk.core.util.MLog;
import com.swgk.core.util.MToast;
import com.swgk.core.util.SharedPreferenceUtil;

import org.greenrobot.eventbus.EventBus;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.inject.Inject;

public class OrganizationAuthActivity extends AppActivity implements ItemInputTextView.OnWholeItemClickListener {

    private Thread thread;
    private static final int MSG_LOAD_DATA = 0x0001;
    private static final int MSG_LOAD_SUCCESS = 0x0002;
    private static final int MSG_LOAD_FAILED = 0x0003;

    private ActivityOrganizationAuthBinding mBinding;

    @Inject
     OrganizationAuthModel mViewModel;

    private List<String> listLicens = new ArrayList<>();

    // 一级联动数据
    private List<AddressEntity<List<AddressEntity<List<AddressEntity<Object>>>>>> addressEntityList = new ArrayList<>();
    // 二级联动数据
    private List<List<AddressEntity<List<AddressEntity<Object>>>>> opt2 = new ArrayList<>();
    // 三级联动数据
    private List<List<List<AddressEntity<Object>>>> opt3 = new ArrayList<>();
    //城市列表
//    private List<AddressEntity<List<AddressEntity>>> cityList;
    //区域列表
    private List<List<AddressEntity<Object>>> areaList;
    private int cityPosition1;
    private int cityPosition2;
    private int cityPosition3;
    private boolean isLoaded = false;
    private String mAreaCode;
    private boolean isEdit;

    private CityPickView cityOption;

    private boolean isCheckBox = false;//是否同意协议
    private boolean isChooseLong = false;//是否选择长期

    private OrganizationAuthEntity mEntity;

    private static final String KEY_ENTITY = "key_entity";

    private Date mCreateDate;//成立日期
    private Date mValidityDate;//有效期

    private List<PickSelectEntity> mOrganizationTypes = new ArrayList<>();

    private OptionsPickerView businessOption;

    private TeamAuthEntity.RealNameUserDTO mRealNameUserDTO;

    private boolean isPersonAuth; //用户是否认证


    public static void launch(Context context){
        Intent intent = new Intent();
        intent.setClass(context, OrganizationAuthActivity.class);
        context.startActivity(intent);
    }

    public static void launch(Context context, OrganizationAuthEntity entity){
        Intent intent = new Intent();
        intent.setClass(context, OrganizationAuthActivity.class);
        intent.putExtra(KEY_ENTITY, entity);
        context.startActivity(intent);
    }

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        super.setupActivityComponent(appComponent);
        DaggerSelfComponent.builder().appComponent(appComponent)
                .selfModule(new SelfModule()).build().inject(this);
    }

    @Override
    protected void initView() {
        super.initView();
        if (getIntent() != null){
            mEntity = (OrganizationAuthEntity) getIntent().getSerializableExtra(KEY_ENTITY);
        }
        mBinding = DataBindingUtil.setContentView(this, R.layout.activity_organization_auth);
        mBinding.include.ivBack.setOnClickListener(v -> {
            finish();
        });
        isPersonAuth = SharedPreferenceUtil.getInstance().getBoolean(SharedPreferenceUtil.PERSON_AUTH, false);
        mBinding.include.titleView.setText("政府/事业单位");
        mBinding.addImg.setOnClickListener(this);
        mBinding.ivCheckBox.setOnClickListener(this);
        mBinding.tvAgree.setOnClickListener(this);
        mBinding.tvFinish.setOnClickListener(this);
        mBinding.tvValidity.setOnClickListener(this);
        mBinding.tvLong.setOnClickListener(this);
        mBinding.itvItemAddress.setOnWholeItemClickListener(this);
        mBinding.itvItemCreateTime.setOnWholeItemClickListener(this);
        mBinding.itvItemMechanismType.setOnWholeItemClickListener(this);
        mBinding.itvItemCode.setInfilterType(ItemInputTextView.TYPE_INDO);
        mBinding.etAddress.setViewOnFocusChangedListener(new CfkEditView.OnFocusChangedListener() {
            @Override
            public void onFocusChanged(View view, boolean focused) {
                if (focused){
                    if (TextUtils.isEmpty(mBinding.itvItemAddress.getContent())){
                        MToast.showToast(OrganizationAuthActivity.this, "请选择机构所在地");
                        mBinding.etAddress.setEnable(false);
                    } else {
                        mBinding.etAddress.setEnable(true);
                    }
                } else {
                    mBinding.etAddress.setEnable(true);
                }
            }
        });

        isEdit = mEntity != null;
        if (mEntity == null){
            mEntity = new OrganizationAuthEntity();
            if (mRealNameUserDTO == null){
                mRealNameUserDTO = new TeamAuthEntity.RealNameUserDTO();
                mRealNameUserDTO.setRealName(SharedPreferenceUtil.getInstance().getBoolean(SharedPreferenceUtil.PERSON_AUTH, false) ? SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.REAL_NAME, "") : "");
                mRealNameUserDTO.setPhone(SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.LOGIN_PHONE, ""));
                mRealNameUserDTO.setIdentityCard(SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.ID_CARD, ""));
            }
            mEntity.setRealNameUserDTO(mRealNameUserDTO);
        } else {
            if (mEntity.getRealNameUserDTO() == null){
                mRealNameUserDTO = new TeamAuthEntity.RealNameUserDTO();
                mRealNameUserDTO.setRealName(mEntity.getUserName());
                mRealNameUserDTO.setPhone(mEntity.getUserPhone());
                mRealNameUserDTO.setIdentityCard(mEntity.getCard());
                mEntity.setRealNameUserDTO(mRealNameUserDTO);
            } else {
                mRealNameUserDTO = mEntity.getRealNameUserDTO();
            }
            editRenderView(mEntity);
        }
        mBinding.setViewModel(mEntity);
        mBinding.itvItemAdminName.setEnable(TextUtils.isEmpty(mRealNameUserDTO.getRealName()));
        mBinding.itvItemAdminCard.setEnable(TextUtils.isEmpty(mRealNameUserDTO.getIdentityCard()));
        mBinding.itvItemAdminPhone.setEnable(TextUtils.isEmpty(mRealNameUserDTO.getPhone()));
        renderLiveData();
    }

    private void editRenderView(OrganizationAuthEntity mEntity) {
        Glide.with(this).load(mEntity.getCodeCertificatePic()).into(mBinding.addImg);
        mBinding.itvItemMechanismType.setContent(mEntity.getInstitutionalTypeName());
        mBinding.itvItemCreateTime.setContent(mEntity.getCreateTime());
        isChooseLong = !TextUtils.isEmpty(mEntity.getLongTimeStr());
        setLongPic();
        mCreateDate = mEntity.getCreateDate();
        mValidityDate = mEntity.getValidityDates();
        mBinding.itvItemAddress.setContent(mEntity.getProvinceName() + mEntity.getCityName() + mEntity.getDistrictName());
        mBinding.etAddress.setEditContent(mEntity.getDetailedAddress());
    }

    private void renderLiveData() {
        mViewModel.getAuthPhotoEntity().observe(this, new Observer<AuthPhotoEntity>() {
            @Override
            public void onChanged(AuthPhotoEntity authPhotoEntity) {
                if (authPhotoEntity == null){
                    listLicens.clear();
                    mBinding.addImg.setImageResource(R.drawable.img_add_pic);
                    mEntity.setCreditCode("");
                    mEntity.setLegalPerson("");
                    mEntity.setOrganizationName("");
                    mEntity.setRegisterDate("");
                    mEntity.setRegisterMoney("");
                    mEntity.setLongTimeStr("");
                    isChooseLong = false;
                    setLongPic();
                } else {
                    //设置数据
                    mEntity.setCodeCertificatePic(authPhotoEntity.getImageUrl());
                    if ("1".equals(authPhotoEntity.getRecognition())){
                        mEntity.setCreditCode(TextUtils.isEmpty(authPhotoEntity.getReg_num()) ? "" : authPhotoEntity.getReg_num());
                        mEntity.setLegalPerson(TextUtils.isEmpty(authPhotoEntity.getPerson()) ? "" : authPhotoEntity.getPerson());
                        mEntity.setOrganizationName(TextUtils.isEmpty(authPhotoEntity.getName()) ? "" : authPhotoEntity.getName());
                        mEntity.setRegisterDate(TextUtils.isEmpty(authPhotoEntity.getEstablish_date()) ? "" : "" + DateUtils.dateTo10Timestamp13(authPhotoEntity.getEstablish_date()));
                        mEntity.setRegisterMoney(TextUtils.isEmpty(authPhotoEntity.getCapital()) ? "" : authPhotoEntity.getCapital());
                        mEntity.setLongTimeStr(TextUtils.isEmpty(authPhotoEntity.getValid_period()) ? "": authPhotoEntity.getValid_period());
                        isChooseLong = !TextUtils.isEmpty(authPhotoEntity.getValid_period());
                        setLongPic();
                    }
                }
                mBinding.setViewModel(mEntity);
            }
        });
        mViewModel.getMAllAddress().observe(this, new Observer<List<AddressEntity<List<AddressEntity<List<AddressEntity<Object>>>>>>>() {
            @Override
            public void onChanged(List<AddressEntity<List<AddressEntity<List<AddressEntity<Object>>>>>> addressEntities) {
                if (!addressEntities.isEmpty()){
                    initAddressData(addressEntities);
                }
            }
        });
        mViewModel.getMessage().observe(this, new Observer<String>() {
            @Override
            public void onChanged(String s) {
                if (!TextUtils.isEmpty(s)){
                    //未认证的用户 组织认证成功 需要刷新
                    if (!isPersonAuth) {
                        SharedPreferenceUtil.getInstance().saveData(SharedPreferenceUtil.PERSON_AUTH, true);
                        AuthenticationEvent authenticationEvent = new AuthenticationEvent();
                        authenticationEvent.setMessageTag(EventConstant.EVENT_USER_AUTHENTICATION);
                        EventBus.getDefault().postSticky(authenticationEvent);
                        EventBus.getDefault().postSticky(LoginEvent.make(EventConstant.EVENT_MAIN_INDEX, 0));  //主动通知刷新消息通讯录数据

                        //给SharedPreferenceUtil中的REAL_NAME赋值 保存实名认证的状态
                        SharedPreferenceUtil.getInstance().saveData(SharedPreferenceUtil.REAL_NAME, mEntity.getRealNameUserDTO().getRealName());
                        //保存个人认证状态
                        SharedPreferenceUtil.getInstance().saveData(SharedPreferenceUtil.ID_CARD, mEntity.getRealNameUserDTO().getIdentityCard());
                    }
                    MToast.showToast(OrganizationAuthActivity.this, s);
                    OrganizationPostSuccess.Companion.launch(OrganizationAuthActivity.this);
                    finish();
                }
            }
        });
        mViewModel.getMOrganTypes().observe(this, new Observer<ArrayList<PickSelectEntity<?>>>() {
            @Override
            public void onChanged(ArrayList<PickSelectEntity<?>> pickFilterEntities) {
                mOrganizationTypes.clear();
                mOrganizationTypes.addAll(pickFilterEntities);
                showTypes();
            }
        });
    }

    public void initAddressData(List<AddressEntity<List<AddressEntity<List<AddressEntity<Object>>>>>> datas) {
        this.addressEntityList.clear();
        addressEntityList.addAll(datas);
        if (isLoaded) {
            showCityPop();
        } else {
            mHandler.sendEmptyMessage(MSG_LOAD_DATA);
        }

    }

    @Override
    public void OnWholeItemClick(View view) {
        switch (view.getId()) {
            case R.id.itv_item_address:
                if (!addressEntityList.isEmpty()) {
                    showCityPop();
                } else {
                    mViewModel.getAddressModel(this);
                }
                break;
            case R.id.itv_item_create_time:
                showTimePop(true);
                break;
            case R.id.itv_item_mechanism_type:
                if (mOrganizationTypes.isEmpty()){
                    mViewModel.getOrganizationTypes(this);
                } else {
                    showTypes();
                }
                break;
        }
    }

    private void showTypes() {
        if (businessOption == null){
            businessOption = new OptionsPickerBuilder(this, (options1, options2, options3, v) -> {
                String content = mOrganizationTypes.get(options1).getProjectscale();
                mBinding.itvItemMechanismType.setContent(content);
                mEntity.setInstitutionalTypeNo(mOrganizationTypes.get(options1).getNo());
            }).setCancelText("取消").setSubCalSize(15)
                    .setCancelColor(getResources().getColor(R.color.color_tab_two))
                    .setTitleText("请选择机构类型")
                    .setTitleColor(getResources().getColor(R.color.color_tab_three)).setTitleSize(15)
                    .setSubmitText("确定")
                    .setSubmitColor(getResources().getColor(R.color.color_main))
                    .build();
        }
        businessOption.setPicker(mOrganizationTypes);
        businessOption.setSelectOptions(0);
        businessOption.show();
    }

    //时间选择器

    /**
     *
     * @param isCreate 是不是成立时间
     */
    public void showTimePop(boolean isCreate) {
        //Calendar startDate = Calendar.getInstance();
       // startDate.set(1900, 0, 1);
        TimePickerView timePicker = new TimePickerBuilder(getActivity(), (date, v) -> {
            @SuppressLint("SimpleDateFormat") SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            if (isCreate){
                if (date.after(new Date())){
                    MToast.showToast(this, "成立日期不能超过当前时间");
                    return;
                }
                if (mValidityDate != null && date.after(mValidityDate)){
                    MToast.showToast(this, "成立日期不能大于有效期");
                    return;
                }
                mCreateDate = date;
            } else {
                if (mCreateDate == null){
                    return;
                }
                if (date.before(mCreateDate)){
                    MToast.showToast(this, "有效期不能小于成立日期");
                    return;
                }
                mValidityDate = date;
            }
            String format = sdf.format(date);
            if (isCreate){
                mBinding.itvItemCreateTime.setContent(format);
                mEntity.setRegisterDate(date.getTime() + "");
            } else {
                mBinding.tvValidity.setText(format);
                isChooseLong = false;
                mEntity.setLongTimeStr("");
                mEntity.setValidityDate(date.getTime() + "");
                setLongPic();
            }

        }).setType(new boolean[]{true, true, true, false, false, false})
               .setCancelText("取消").setSubCalSize(15)
                .setCancelColor(getResources().getColor(R.color.color_tab_two))
                .setTitleText(isCreate ? "请选择成立日期" : "请选择有效期")
                .setTitleColor(getResources().getColor(R.color.color_tab_three)).setTitleSize(15)
                .setSubmitText("确定")
                .setSubmitColor(getResources().getColor(R.color.color_main)).build();
        timePicker.show();
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.add_img:
                pictureSelector(true, 500, 1);
                break;
            case R.id.iv_check_box:
                if (isCheckBox){
                    mBinding.ivCheckBox.setImageResource(R.drawable.icon_no_select_item);
                    isCheckBox = false;
                } else {
                    isCheckBox = true;
                    mBinding.ivCheckBox.setImageResource(R.drawable.icon_select_checkbox_item);
                }
                break;
            case R.id.tv_agree:
                WebActivity.start(getActivity(), Constants.SUPPLIER_URL);
                break;
            case R.id.tv_long:
                if (isChooseLong){
                    mEntity.setLongTimeStr("");
                    isChooseLong = false;
                } else {
                    mEntity.setLongTimeStr("长期");
                    isChooseLong = true;
                }
                setLongPic();
                break;
            case R.id.tvFinish:
                if (!ClickUtils.isDoubleClick()){
                    validate();
                }
                break;
            case R.id.tv_validity:
                if (TextUtils.isEmpty(mBinding.itvItemCreateTime.getContent())){
                    MToast.showToast(this, "请先选择成立日期");
                } else {
                    showTimePop(false);
                }
                break;

        }
    }

    private void setLongPic() {
        mBinding.tvLong.setCompoundDrawablesRelativeWithIntrinsicBounds(getResources().getDrawable(isChooseLong ? R.drawable.icon_select_checkbox_item : R.drawable.icon_no_select_item), null, null, null);
        if (isChooseLong){
            mBinding.tvValidity.setText("");
            mEntity.setValidityDate("");
        } else {
            mBinding.tvValidity.setText((mEntity == null) ? "" : mEntity.getValidityTime());
        }
    }

    private void validate() {
        if (TextUtils.isEmpty(mEntity.getCodeCertificatePic())){
            MToast.showToast(this, "请上传社会信用代码证书");
            return;
        }
        if (TextUtils.isEmpty(mBinding.itvItemName.getContent())){
            MToast.showToast(this, "请输入政府/单位名称");
            return;
        }
        if (TextUtils.isEmpty(mBinding.itvItemCode.getContent())){
            MToast.showToast(this, "请输入信用代码");
            return;
        }
        if (mBinding.itvItemCode.getContent().length() != 15 &&  mBinding.itvItemCode.getContent().length() != 18){
            MToast.showToast(this, "请输入18位或15位信用代码");
            return;
        }
        if (TextUtils.isEmpty(mBinding.itvItemLegalPerson.getContent())){
            MToast.showToast(this, "请输入法定代表人");
            return;
        }
        if (TextUtils.isEmpty(mBinding.itvItemMechanismType.getContent())){
            MToast.showToast(this, "请选择机构类型");
            return;
        }
        if (TextUtils.isEmpty(mBinding.itvItemRegisterMoney.getContent())){
            MToast.showToast(this, "请输入注册资金");
            return;
        }
        if (TextUtils.isEmpty(mBinding.itvItemCreateTime.getContent())){
            MToast.showToast(this, "请选择成立日期");
            return;
        }
        if (TextUtils.isEmpty(mBinding.tvValidity.getText().toString()) && !isChooseLong){
            MToast.showToast(this, "请选择有效日期或者长期");
            return;
        }
        if (TextUtils.isEmpty(mBinding.itvItemAddress.getContent())){
            MToast.showToast(this, "请选择注册地址");
            return;
        }
        if (TextUtils.isEmpty(mBinding.etAddress.getEditContent())){
            MToast.showToast(this, "请输入详细");
            return;
        }
        if (TextUtils.isEmpty(mBinding.itvItemAdminPhone.getContent())){
            MToast.showToast(this, "请输入管理员手机号码");
            return;
        }
        if (TextUtils.isEmpty(mBinding.itvItemAdminName.getContent())){
            MToast.showToast(this, "请输入管理员姓名");
            return;
        }
        if (TextUtils.isEmpty(mBinding.itvItemAdminCard.getContent())){
            MToast.showToast(this, "请输入管理员身份证号");
            return;
        }
        if (!isCheckBox){
            MToast.showToast(this, "请先阅读经营帮组织认证协议");
            return;
        }
        mEntity.setDetailedAddress(mBinding.etAddress.getEditContent());
        mEntity.setStatus(1);//默认设为待审核
        mViewModel.saveOrUpdateOrganization(this, mEntity);
    }

    @Override
    protected void onPictureSelectorResult(List<LocalMedia> selectList) {
        super.onPictureSelectorResult(selectList);
        if (selectList == null || selectList.size() <= 0){
            selectList = new ArrayList<>();
        }
        File file = new File(selectList.get(0).getRealPath());
        MLog.d("图片路径：", selectList.get(0).getRealPath());
        if (file.exists()) {
            MLog.d("图片", "存在");
        }
        listLicens.clear();
        listLicens.add(selectList.get(0).getRealPath());
        Glide.with(getActivity()).load(selectList.get(0).getRealPath()).into(mBinding.addImg);
        mViewModel.upLicenseModel(this, file);
    }


    @SuppressLint("HandlerLeak")
    private Handler mHandler = new Handler() {
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case MSG_LOAD_DATA:
                    if (thread == null) {
                        thread = new Thread(new Runnable() {
                            @Override
                            public void run() {
                                // 子线程中解析省市区数据
                                initJsonData();
                            }
                        });
                        thread.start();
                    }
                    break;
                case MSG_LOAD_SUCCESS:
                    showCityPop();
                    isLoaded = true;
                    break;

                case MSG_LOAD_FAILED:
                    break;
            }
        }
    };


    private void initJsonData() {

        for (int i = 0; i < addressEntityList.size(); i++) {

            if (isEdit) {
                if (addressEntityList.get(i).getId().equals(mEntity.getProvinceNo())) {
                    cityPosition1 = i;
                }
            }

//            cityList = new ArrayList<>();
            areaList = new ArrayList<>();
            opt2.add(addressEntityList.get(i).getChildren());
            for (int j = 0; j < addressEntityList.get(i).getChildren().size(); j++) {

                if (isEdit) {
                    if (addressEntityList.get(i).getChildren().get(j).getId().equals(mEntity.getCityNo())) {
                        cityPosition2 = j;
                    }
                }
                List<AddressEntity<Object>> cityAreaList = new ArrayList<>();
                List<AddressEntity<Object>> children = addressEntityList.get(i).getChildren().get(j).getChildren();
                if (children == null || children.size() == 0) {
                    cityAreaList.add(null);
                } else {
                    cityAreaList.addAll(children);
                    if (isEdit) {
                        for (int k = 0; k < children.size(); k++) {
                            if (children.get(k).getId().equals(mEntity.getDistrictNo())) {
                                cityPosition3 = k;
                            }
                        }
                    }
                }
                areaList.add(cityAreaList);
            }
            opt3.add(areaList);
        }

        mHandler.sendEmptyMessage(MSG_LOAD_SUCCESS);
    }


    private void showCityPop() {
        if (cityOption == null) {
            cityOption = new CityPickBuilder(OrganizationAuthActivity.this, new OnOptionsSelectListener() {
                @Override
                public void onOptionsSelect(int options1, int options2, int options3, View v) {
                    String areaName;
                    if (opt3.get(options1).get(options2).get(options3) == null) {
                        areaName = "";
                    } else {
                        areaName = opt3.get(options1).get(options2).get(options3).getName();
                        mAreaCode = opt3.get(options1).get(options2).get(options3).getNo();
                        cityPosition3 = options3;
                        mEntity.setDistrictNo(mAreaCode);
                    }
                    String content = addressEntityList.get(options1).getName() + opt2.get(options1).get(options2).getName() + areaName;
                    mBinding.itvItemAddress.setContent(content);
                    mEntity.setCityNo(opt2.get(options1).get(options2).getNo());
                    mEntity.setProvinceNo(addressEntityList.get(options1).getNo());
                    cityPosition1 = options1;
                    cityPosition2 = options2;

                }
            }).setCancelText("取消").setSubCalSize(15)
                    .setCancelColor(getResources().getColor(R.color.color_tab_two))
                    .setSubmitText("确定")
                    .setSubmitColor(getResources().getColor(R.color.color_main)).build();
        }
        cityOption.setPicker(addressEntityList, opt2, opt3);
        cityOption.setSelectOptions(cityPosition1, cityPosition2, cityPosition3);
        cityOption.show();
    }
}
